# SleepMirror - A reflection of your sleep quality
# 
# sm_test.rb
# 
# This is the basic class that represents a single test that a participant 
# will take.  This is intended to be a base class that is extened by other
# specialty classes.  For example,  Perception Tests, Motion Test, Audible Test
# and so forth.
# TODO: add persistance logic to write out data.
# 
# ©2010 JohnGary, LLC.  All Rights Reserved.
# 
# 
# Changelog:
# 
# 
# 

require 'sm_util'
require 'rubygame'
include Rubygame
include Rubygame::Events
include Rubygame::EventTriggers
include Rubygame::EventActions


class SM_panel

  include Rubygame::EventHandler::HasEventHandler

  attr_accessor :uid, :name, :instructions, :asset, :answer, :hooks

  # SM_panel is the fundamental base class for individual tests that are taken
  # by a Participant.  Subclasses should override the perform method, and are
  # expected to be specializations such as SM_visual_truefalse, SM_motion_test, etc.
  # * name is the human readable id.
  # * instructions is a big ol' string of what to do for this test.
  # * asset is the image or other asset the test needs.  Just one for now.
  def initialize (name="noname", instructions="no instructions", asset="no asset")
    @uid = SM_util.gen_uuid()
    @name, @instructions, @asset = name, instructions, asset
    # 'answer' is the expected correct reply for the given test.
    @answer=nil
    # Initialize Rubygame, and clean up when script exits.
    Rubygame.init
    at_exit { Rubygame.quit }

    make_magic_hooks(  :escape       => :exit_script,
                       :mouse_right  => :exit_script,
                       QuitRequested => :exit_script
                    )
  end
  # Each subclass is expected to override this method with their own implementation.
  # Here it only raises a NotImplementedError.
  def perform
      raise NotImplementedError
    end
  # This is the default exit point for SM_panel.  At the base class level it just
  # calls 'exit'.  Subclasses can override as needed.
  # BEWARE:  'exit' will shut down for the application.  If there is a calling,
  # orchestrator of some time, it should 'resuce SystemExit' after invoking the
  # 'perform' method of an SM_panel.  This will allow the calling code to contine
  # to run.
  def exit_script
    exit
  end
end
